package com.wenhao.leetcode.easy;

public class Foo2 {
    private volatile Integer firstJobDone = 0;
    private volatile Integer secondJobDone = 0;

    public Foo2() {

    }

    public void first(Runnable printFirst) throws InterruptedException {

        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        firstJobDone++;
    }

    public void second(Runnable printSecond) throws InterruptedException {
        while (firstJobDone == 0) {

        }
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        secondJobDone++;
    }

    public void third(Runnable printThird) throws InterruptedException {
        while (secondJobDone == 0) {

        }
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }
}
